#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
class Solution {
public:
    int lastStoneWeight(vector<int>& stones)
    {
        priority_queue<int> heap;
        for (auto x : stones) heap.push(x);

        while (heap.size() > 1)
        {
            int a = heap.top();
            heap.pop();
            int b = heap.top();
            heap.pop();
            if (a > b) heap.push(a - b);

        }
        return heap.size() ? heap.top() : 0;
    }
};